﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Bricks.Component.Utils;
using Bricks.Business.Models.Account;
using Bricks.Site.Models;

using Webdiyer.WebControls.Mvc;
using Bricks.Business.Service;
using Bricks.Site.Models.ParamSetting;
using Bricks.Component.Utils.Const;


namespace Bricks.Site.Web.Controllers
{
    /// <summary>
    /// 参数设置Controllor
    /// </summary>
    [Export]
    public class ParamSettingController : BaseController
    {
        [Import]
        public IParamSettingService ParamSettingService { get; set; }

        /// <summary>
        /// 系统参数
        /// </summary>
        /// <returns></returns>
        public ActionResult SystemParam()
        {
            SystemParamView view = new SystemParamView();
            view.SystemName = ParamSettingService.GetContentByGroupAndTag(ParamSettingGroup.SystemParam, ParamSettingTag.SystemName);  //系统名称
            view.SystemKey = ParamSettingService.GetContentByGroupAndTag(ParamSettingGroup.SystemParam, ParamSettingTag.SystemKey);  //系统密钥
            view.SystemCopyright = ParamSettingService.GetContentByGroupAndTag(ParamSettingGroup.SystemParam, ParamSettingTag.SystemCopyright);  //系统版权
            return View(view);

        }

        /// <summary>
        /// 系统参数（Post）
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ValidateInput(false)]  //添加这个是为了防止错误：从客户端中检测到有潜在危险的 Request.Form 值
        public ActionResult SystemParamPost(SystemParamView view)
        {
            OperationResult result = ParamSettingService.SaveSystemParam(view);
            return Json(result, "text/html");
        }
    }
}
